<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/28
 * Time: 12:26
 */

/**
 * Class Involved_LogisticsStatusModel
 */

class Involved_NewResourceModel extends BaseModel{

    protected $table = 'new_resource';


    /**
     * 商城产品列表
     * @param $paramObj
     * @return mixed
     */

    public function NewResourceList($paramObj){

        $db = DB::table($this->table);
        #筛选
        //关键字
        if (!empty($paramObj->key_word)) {
            $db->where('product_name', 'like', "%{$paramObj->key_word}%");
        }
        //仓储地
        if (property_exists($paramObj,'storage') && !empty($paramObj->storage)) {
            $db->where('storage', $paramObj->storage);
        }

        #查询
        $goods =  $db
            ->select('product_id','product_name','spec','storage','price','created','start_num','unit','stock')
            ->where('status',1)
            ->paginate(20);
        return $goods;

    }

    /**
     * 现货产品详情
     * @param $paramObj
     * @return mixed
     */

    public function NewResourceDetails($paramObj){

        #查询
        return DB::table($this->table)
            ->where('product_id',$paramObj->product_id)
            ->first();

    }

    /**
     * 根据用户ID，查现货
     * @param $user_id
     * @return mixed
     */

    public function UserNowResourceList($user_id){

        #查询
        return DB::table($this->table)
            ->select('product_id','product_name','spec','storage','price','created','start_num','unit','stock','status')
            ->where('user_id',$user_id)
            ->paginate(10);
    }


}
